import React, { Component } from 'react'
import './index.css'

export default class Demo extends Component {
  render() {
    return (
      <div className="parent">
        <h2>我是 parent 组件</h2>
        <A render={(name) => <B name={name} />} />
      </div>
    )
  }
}

class A extends Component {
  state = {
    name: 'zxn',
    age: 18
  }
  render() {
    console.log('a', this.props)
    const { name } = this.state
    return (
      <div className="a">
        <h2>我是 A 组件</h2>
        {this.props.render(name)}
      </div>
    )
  }
}

class B extends Component {
  render() {
    console.log('b', this.props)
    const { name } = this.props
    return (
      <div className="b">
        <h2>我是 B 组件</h2>
        <div>我是父组件中传递的参数 {name}</div>
      </div>
    )
  }
}
